//
//  MBDPath2URLUtils.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/14.
//

import Foundation


class MBDPath2URLUtils : NSObject {
    static let placeHolderGroupLogoPath = filePathPrefix.appending("AppIcon")
    static let placeHolderAvatarPath = filePathPrefix.appending("AppIcon")
    static let filePathPrefix = "file://"
    
    static func wrapGroupLogoURL(path: String?) -> String {
        guard let realPath = path else {
            return placeHolderGroupLogoPath
        }
        
        if realPath.isBlank == true {
            return placeHolderGroupLogoPath
        }
        
        if realPath.hasPrefix(MBDPath2URLUtils.filePathPrefix) {
            return placeHolderGroupLogoPath
        }
        
        if realPath.hasPrefix("http") == false {
            if realPath.hasPrefix("/") {
                return MBDHostManager.shared.imageHost + realPath
            } else {
                return MBDHostManager.shared.imageHost + "/" + realPath
            }
        }
        
        return realPath
    }
    
    
    static func wrapAvatarURL(path: String?) -> String {
        guard let realPath = path else {
            return placeHolderAvatarPath
        }
        
        if realPath.isBlank == true {
            return placeHolderAvatarPath
        }
        if realPath.hasPrefix("http") == false {
            if realPath.hasPrefix("/") {
                return MBDHostManager.shared.imageHost + realPath
            } else {
                return MBDHostManager.shared.imageHost + "/" + realPath
            }
        }
        
        return realPath
    }
}
